
 // let baseURL = "http://wrtest.axa2.com/"
  // let baseURL = "http://wrtest.axa2.com/"
let baseURL = "https://yhz.axu9.com/"
let uploadAudioUrl = "data/api.upload/file";//上传音频
let uploadImgUrl = "data/api.upload/file";//上传图片
let token = ""; // 一般用户的token 
let volunteerToken = ""; // 志愿者固有的token 
export const myRequest = (options) => {  
	return new Promise((resolve, reject) => {  
		// console.log(baseURL + options.url,'请求++++++++++++++++++++');
		uni.request({    url: baseURL + options.url, //接口地址：前缀+方法中传入的地址    
		method: options.method || "GET", //请求方法：传入的方法或者默认是“GET”    
		data: options.data || {}, //传递参数：传入的参数或者默认传递空集合    
		dataType: 'text',
		header: {},     
		success: (res) => {     //返回的数据（不固定，看后端接口，这里是做了一个判断，如果不为true，用uni.showToast方法提示获取数据失败)     // 如果不满足上述判断就输出数据     
			console.log(res)
			let aa = res.data
			let jsonString = aa.replace(/﻿/g, '');
			let data = JSON.parse(jsonString)
			if (data.code == 1 || data.code == 0 || data.code == 200) {      
				resolve(data)
			} else {   
				 reject(data);
			}    
		},    // 这里的接口请求，如果出现问题就输出接口请求失败    
		fail: (err) => {     
			// console.log(err)    
			reject(err)    
			},
		})  
	}) 
}


//图片上传
export function uploadImg(types) {
	return new Promise((resolve, reject) => {
		uni.chooseImage({
			count: 1,
			sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			sourceType: ['album', 'camera'], //从相册选择
			type: 'image',
			extension:['.png','jpg'],
			success: (res) => {
				console.log(res,'上传图片')
				const tempFilePaths = res.tempFilePaths[0];
				const uploadTask = uni.uploadFile({
					url: baseURL + uploadImgUrl, //图片上传地址
					formData: {
						// 'folderType': types
					},
					filePath: tempFilePaths,
					name: 'file',
					success: (uploadFileRes) => {
						
						let logo = JSON.parse(uploadFileRes.data);
						console.log(logo,'logo')
						resolve(logo)
					}
				});
			},
			error: (e) => {
				reject(e)
			}
		});
	});
}

//音频上传
export function uploadAudio(types) {
	return new Promise((resolve, reject) => {
		// console.log(types,'types')
		const tempFilePaths = types;
		// console.log(tempFilePaths,'tempFilePaths')
		const uploadTask = uni.uploadFile({
			url: baseURL + uploadAudioUrl, //图片上传地址
			formData: {
				// 'folderType': types
			},
			filePath: tempFilePaths,
			name: 'file',
			success: (uploadFileRes) => {
				// console.log(JSON.parse(uploadFileRes.data),'JSON.parse(uploadFileRes.data)')
				let logo = JSON.parse(uploadFileRes.data).data;
				let name = types.split("/").slice(-1)
				// console.log(logo,name,'logo')
				let data = {
					res: logo,
					name: name[0]
				}
				resolve(data)
			}
		});
		// uni.chooseImage({
		// 	count: 1,
		// 	sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
		// 	sourceType: ['album', 'camera'], //从相册选择
		// 	success: (res) => {
		// 		const tempFilePaths = res.tempFilePaths;
		// 		const uploadTask = uni.uploadFile({
		// 			url: baseURL + uploadAudioUrl, //图片上传地址
		// 			formData: {
		// 				'folderType': types
		// 			},
		// 			filePath: tempFilePaths[0],
		// 			name: 'file',
		// 			success: (uploadFileRes) => {
						
		// 				let logo = JSON.parse(uploadFileRes.data);
		// 				console.log(logo,'logo')
		// 				resolve(logo)
		// 			}
		// 		});
		// 	},
		// 	error: (e) => {
		// 		reject(e)
		// 	}
		// });
	});
}


